package com.mg.framework.kernel;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;

public abstract class BaseActor {

	private float x = 0f;
	private float y = 0f;
	Matrix matrix = null;
	Paint paint = null;

	private boolean rotateIsOpen = false;

	private float rotate_x = 0f;
	private float rotate_y = 0f;
	private float rotate_degree = 0f;

	private boolean scaleIsOpen = false;

	private float scale_sx = 0f;
	private float scale_sy = 0f;
	private float scale_x = 0f;
	private float scale_y = 0f;

	BaseActor() {
		this.matrix = new Matrix();
		this.paint = new Paint();
		this.paint.setAntiAlias(true);
		this.paint.setFilterBitmap(true);
	}

	protected void setX(float x) {
		this.x = x;
	}

	protected float getX() {
		return this.x;
	}

	protected void setY(float y) {
		this.y = y;
	}

	protected float getY() {
		return this.y;
	}

	protected boolean isRotateIsOpen() {
		return rotateIsOpen;
	}

	protected boolean isScaleIsOpen() {
		return scaleIsOpen;
	}

	protected void addX(float offsetX) {
		this.x += offsetX;
	}

	protected void addY(float offsetY) {
		this.y += offsetY;
	}

	protected void reduceX(float offsetX) {
		this.x -= offsetX;
	}

	protected void reduceY(float offsetY) {
		this.y -= offsetY;
	}

	protected void setXY(float x, float y) {
		this.x = x;
		this.y = y;
	}

	protected void closeMatrix() {
		this.rotateIsOpen = false;
		this.scaleIsOpen = false;
	}

	protected void Rotate(float degree, float px, float py) {
		if (!this.rotateIsOpen) {
			this.rotateIsOpen = true;
		}
		this.rotate_degree = degree;
		this.rotate_x = px;
		this.rotate_y = py;
	}

	protected void Scale(float sx, float sy, float px, float py) {
		if (!this.scaleIsOpen) {
			this.scaleIsOpen = true;
		}
		this.scale_sx = sx;
		this.scale_sy = sy;
		this.scale_x = px;
		this.scale_y = py;
	}

	Matrix flipHorizontally(int width, int height) {
		Matrix matrix = new Matrix();
		matrix.postScale(-1, 1, width / 2, height / 2);
		matrix.postTranslate(this.x, this.y);
		return matrix;
	}

	Matrix flipVertically(int width, int height) {
		Matrix matrix = new Matrix();
		matrix.postScale(1, -1, width / 2, height / 2);
		matrix.postTranslate(this.x, this.y);
		return matrix;
	}

	void drawSelf() {
		this.matrix.reset();
		if (this.isScaleIsOpen()) {
			this.matrix.postScale(this.scale_sx, this.scale_sy, this.scale_x,
					this.scale_y);
		}
		if (this.isRotateIsOpen()) {
			this.matrix.postRotate(this.rotate_degree, this.rotate_x,
					this.rotate_y);
		}
		this.matrix.postTranslate(this.x, this.y);
	}

	public abstract void gameUpdate();

	public abstract void screenUpdate(Canvas canvas);
}
